package com.gitee.wsl.platform.thread.lock


import java.util.concurrent.locks.ReentrantLock

internal data class JvmMutexHandle(
    val value: ReentrantLock
) : MutexHandle

internal actual fun createMutex(): MutexHandle = JvmMutexHandle(ReentrantLock())

internal actual fun lockMutex(handle: MutexHandle) {
    require(handle is JvmMutexHandle)
    handle.value.lock()
}

internal actual fun tryLockMutex(handle: MutexHandle): Boolean {
    require(handle is JvmMutexHandle)
    return handle.value.tryLock()
}

internal actual fun unlockMutex(handle: MutexHandle) {
    require(handle is JvmMutexHandle)
    return handle.value.unlock()
}